<template>
  <div class="app-container">

    <!--form 组件-->
    <eForm ref="form"/>
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="initMethod"/>
      <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
        <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="initMethod">搜索</el-button>
      <!-- 新增 -->
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="tableData.content" stripe border size="small" style="width: 100%;">
      <el-table-column prop="id" label="用户ID"/>
      <el-table-column prop="accountId" label="账户ID"/>
      <el-table-column prop="avatarUrl" label="头像">
      <template slot-scope="scope"><el-avatar :size="50" :src="scope.row.avatarUrl" shape="square" /></template></el-table-column>
      <el-table-column prop="name" label="姓名"/>
      <el-table-column prop="nickName" label="昵称" show-overflow-tooltip/>
      <el-table-column prop="type" label="用户类型"/>
      <el-table-column prop="level" label="级别"/>
      <el-table-column prop="openid" label="openid" width="150px" show-overflow-tooltip align="center"/>
      <el-table-column prop="created" label="创建时间" width="150px" show-overflow-tooltip/>
      <el-table-column prop="account.balance" label="余额" align="center"/>
      <el-table-column prop="account.cumulative" label="累计金额" align="center"/>
      <el-table-column prop="account.bonus" label="赠送金额" align="center"/>
      <el-table-column prop="account.integral" label="积分" align="center"/>
      <el-table-column prop="city" label="城市" show-overflow-tooltip/>
      <el-table-column prop="country" label="国家" show-overflow-tooltip/>
      <el-table-column
        :filters="[{ text: '男性', value: '男性' }, { text: '女性', value: '女性' }, { text: '未知', value: '未知' }]"
        :filter-method="filterTag"
        prop="gender"
        label="性别"
        filter-placement="bottom-end"/>
      <el-table-column prop="language" label="语言"/>
      <el-table-column prop="province" label="省份" show-overflow-tooltip/>
      <el-table-column prop="sessionKey" label="sessionKey" show-overflow-tooltip/>
      <el-table-column prop="unionid" label="unionid" show-overflow-tooltip/>
      <el-table-column label="操作" fixed="right" width="150px" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="editAccount(scope.row.account)"/>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <div class="block">
      <el-pagination
        :current-page="query.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="query.size"
        :total="tableData.totalElements"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import eForm from './form'
import { postRequest } from '@/api/identity'
export default {
  components: { eForm },
  data() {
    return {
      loading: false,
      delLoading: false,
      centerDialogVisible: false,
      query: {
        value: '',
        type: '',
        page: 1,
        size: 10
      },
      tableData: {
        totalElements: 0,
        data: []
      },
      queryTypeOptions: [
        { key: 'id', display_name: '用户ID' },
        { key: 'name', display_name: '姓名' },
        { key: 'nickName', display_name: '昵称' },
        { key: 'openid', display_name: 'openid' }
      ]
    }
  },
  created() {
    this.$nextTick(() => {
      this.initMethod()
    })
  },
  methods: {
    checkPermission,
    initMethod() {
      postRequest('pc/identity', this.query).then(resp => {
        console.log(resp)
        this.tableData = resp.entity
      })
    },
    handleSizeChange(val) {
      this.query.size = val
      this.initMethod()
    },
    handleCurrentChange(val) {
      this.query.page = val
      this.initMethod()
    },
    editAccount(val) {
      const _this = this.$refs.form
      _this.form = val
      _this.dialog = true
    },
    filterTag(value, row) {
      return row.gender === value
    }
  }
}
</script>

<style scoped>

</style>
